
import { createRouter, createWebHistory } from "vue-router"
import Layout from '@/views/layout/index.vue'
import component from "element-plus/es/components/tree-select/src/tree-select-option.mjs";
const routes = [
	// 默认页面
	{
		path: '/',
		redirect: '/login',
	},
	{
		path: '/login',
		name: 'login',
		component: () => import('@/views/login/index.vue')
	},
	//注册
	{
		path: '/register',
		name: 'register',
		component: () => import('@/views/register/index.vue')
	},
	{
		path: '/:pathMatch(.*)*',
		name: 'AllNotFound',
		component: () => import('@/views/404/index.vue')
	},
	// 组件出口
	{
		component: Layout,
		path: "/",
		children: [
			{
				path: "/home",
				name: "home",
				meta: {
					title: '首页',
					icon: 'House'
				},
				/** 在src/views 文件下创建home文件 */
				component: () => import("@/views/home/index.vue"),
			},
			{
				path: "/system",
				name: "system",
				meta: {
					title: '实训活动',
					icon: 'Grid'
				},
				/** 在src/views 文件下创建system文件 */
				component: () => import("@/views/system/index.vue"),
			},
			{
				path: "/userManagement",
				name: "userManagement",
				meta: {
					title: '机构管理',
					icon: 'Avatar'
				},
				/** 在src/views 文件下创建userManagement文件 */
				component: () => import("@/views/userManagement/index.vue"),
				children: [{
					path: "/productAdministrator",
					name: "productAdministrator",
					meta: {
						title: '产品管理',
						icon: 'TakeawayBox'
					},
					/** 在src/views 文件下创建productAdministrator文件 */
					component: () => import("@/views/userManagement/productAdministrator/index.vue"),
				},
				{
					path: "/productAdministratorInfo",
					name: "productAdministratorInfo",
					meta: {
						title: '产品信息',
						icon: 'TakeawayBox'
					},
					/** 在src/views 文件下创建productAdministratorInfo文件 */
					component: () => import("@/views/userManagement/productAdministratorInfo/index.vue"),
				}
				]
			},
			{
				path: "/productManagement",
				name: "productManagement",
				meta: {
					title: '场地管理',
					icon: 'TakeawayBox'
				},
				/** 在src/views 文件下创建productManagement文件 */
				component: () => import("@/views/productManagement/index.vue"),
			},

			// 场地申请 Venue application
			{
				path: "/information",
				name: "information",
				meta: {
					title: '人才招聘',
					icon: 'ChatLineSquare'
				},
				/** 在src/views 文件下创建information文件 */
				component: () => import("@/views/information/index.vue"),
			},
			{
				path: "/contract",
				name: "contract",
				meta: {
					title: '认证服务',
					icon: 'Tickets'
				},
				/** 在src/views 文件下创建contract文件 */
				component: () => import("@/views/contract/index.vue"),
			},
			// {
			// 	path: "/operation",
			// 	name: "operation",
			// 	meta: {
			// 		title: '操作日志',
			// 		icon: 'Pointer'
			// 	},
			// 	/** 在src/views 文件下创建operation文件 */
			// 	component: () => import("@/views/operation/index.vue"),
			// },
			// {
			// 	path: "/conLog",
			// 	name: "conLog",
			// 	meta: {
			// 		title: '登录日志',
			// 		icon: 'Document'
			// 	},
			// 	/** 在src/views 文件下创建conLog文件 */
			// 	component: () => import("@/views/conLog/index.vue"),
			// },
			{
				path: "/setting",
				name: "setting",
				meta: {
					title: '系统管理',
					icon: 'Setting'
				},
				/** 在src/views 文件下创建setting文件 */
				component: () => import("@/views/setting/index.vue"),
			},
			{
				path: "/myTodoList",
				name: "myTodoList",
				meta: {
					title: '我的代办',
					icon: 'Calendar'
				},
				component: () => import("@/views/myTodoList/index.vue"),
			},
			{
				path: "/addtraining",
				name: "addtraining",
				component: () => import("@/views/system/addtraining.vue")
			},
			// 动态form表单组件
			{
				path: '/siteForm',
				name: 'siteForm',
				component: () => import('@/views/productManagement/siteForm.vue')
			}
			,
			{
				path: '/activityDetail:id?',
				name: 'activityDetail',
				component: () => import('@/views/system/activityDetail.vue')
			},

			// {
			// 	path: '/VenueApplication',
			// 	name: 'VenueApplication',
			// 	meta: {
			// 		title: '',
			// 		icon: ''
			// 	},
			// 	component: () => import('@/views/productManagement/VenueApplication.vue')
			// }
		]
	},
];

const router = createRouter({
	history: createWebHistory(),
	routes: routes.concat(routes),
	//路由懒加载
	//使用浏览器的回退或者前进时，重新返回时保留页面滚动位置，跳转页面的话，不触发。
	scrollBehavior(to, from, savePosition) {
		if (savePosition) {
			return savePosition;
		} else {
			return { top: 0 };
		}
	}
});

// // 登录验证，强制转跳登录页
// router.beforeEach((to, from, next) => {
// 	// useCounterStore = useCounter()

// 	// 获取浏览器 cookie
// 	const sid = getCookie("SESSIONID")
// 	// 重定向到登录页和大屏页面特殊放行
// 	// if (to.name === "Login") {
// 	// 	if (sid) {
// 	// 		return next({ path: "/" })
// 	// 	} else {
// 	// 		return next()
// 	// 	}
// 	// }
// 	// 免认证登录
// 	if (Object.prototype.hasOwnProperty.call(to.query, "auth")) {
// 		return next()
// 	}

// 	if (!sid || !sid.length) {
// 		// 跳第2个登录页  关基需求需要
// 		if (to.fullPath === "/register") {
// 			return next({ name: "Login2", replace: true })
// 		} else {
// 			return next({ name: "Login", replace: true })
// 		}
// 	}
// 	return next()
// })

// function checkIdentity(identity) {
// 	return (to) => {
// 		// 免认证登录
// 		if (!useCounterStore?.identity && Object.prototype.hasOwnProperty.call(to.query, "auth")) {
// 			return true
// 		}
// 		// 验证身份
// 		if (+useCounterStore?.identity !== identity) {
// 			return { path: "/" }
// 		}
// 	}
// }

// function getCookie(name) {
// 	const arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"))
// 	if (arr !== null) {
// 		return arr[2] + ""
// 	} else {
// 		return null
// 	}
// }

export default router;



